package sd.qd.xiaoming.coffeedesk.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import sd.qd.xiaoming.coffeedesk.entity.CdNoteType;
import sd.qd.xiaoming.coffeedesk.service.CdNoteTypeService;

@Controller
@RequestMapping("/note_type")
public class CdNoteTypeController {

    @Autowired
    private CdNoteTypeService cdNoteTypeService;

    @ResponseBody
    @RequestMapping("/get_all_types")
    public Object getAllTypes() {
        List<CdNoteType> list = this.cdNoteTypeService.findAll();
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        for (CdNoteType type : list) {
            Map<String, Object> node = new HashMap<String, Object>();
            node.put("id", type.getId());
            node.put("text", type.getName());
            node.put("attributes", type.getCode());
            result.add(node);
        }
        return result;
    }

}
